package com.xc.h05.service.weichen.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.xc.h05.entity.Consult;
import com.xc.h05.entity.ConsultSpecialty;
import com.xc.h05.entity.Specialty;
import com.xc.h05.mapper.ConsultMapper;
import com.xc.h05.mapper.ConsultSpecialtyMapper;
import com.xc.h05.mapper.SpecialtyMapper;
import com.xc.h05.service.weichen.SpecialtyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SpecialtyServiceImpl implements SpecialtyService {
    @Autowired
    private SpecialtyMapper specialtyMapper;
    @Autowired
    private ConsultSpecialtyMapper consultSpecialtyMapper;
    @Autowired
    private ConsultMapper consultMapper;
    @Override
    public int add(Specialty specialty) {
        int add = specialtyMapper.add(specialty);
        return add ;
    }

    @Override
    public int delete(int id) {
        int delete = specialtyMapper.delete(id);
        return delete;
    }

    @Override
    public int deletes(List list) {
        int deletes = specialtyMapper.deletes(list);
        return deletes;
    }

    @Override
    public int update(Specialty specialty) {
        int update = specialtyMapper.update(specialty);
        return update;
    }

    @Override
    public PageInfo<Specialty> findByPage(int pageNum, int pageSize, Specialty specialty) {
        PageHelper.startPage(pageNum,pageSize);
        List<Specialty> list = specialtyMapper.findByPage(specialty);
        for (Specialty s : list) {
            //得到擅长领域对应的多个咨询师id
            List list1 = consultSpecialtyMapper.findById(s.getId());
            if (list1.size()==0){
                s.setConsult(list1);
            }else {
                List<Consult> consultList = consultMapper.findByIds(list1);
                s.setConsult(consultList);
                System.out.println(s);
            }
        }
        PageInfo<Specialty> pageInfo = new PageInfo<>(list);
        return pageInfo;
    }

    @Override
    public List<Specialty> findAll() {
        List<Specialty> list = specialtyMapper.findAll();
        return list;
    }


}
